package structures;

import pack.MyReader;

public class ExtendedSerialNumber extends TypeAbstract{
	
	public final static int size = 8;
	public final int serialNumber; //int (4)
	public final String monthYear; //BCDString (2)
	public final String type; //Octet String (1)
	public final ManufacturerCode manufacturerCode; //int (1)
	
	public ExtendedSerialNumber(MyReader reader){
		serialNumber = reader.readInt(4);
		monthYear = reader.readBcd(2);
		//type = reader.readOctet(1);
		type = reader.readHex(1);
		manufacturerCode = new ManufacturerCode(reader);
	}
	
	public String toString()
	{
		return Integer.toString(serialNumber)
			+ "-"
			+ monthYear 
			+ "-"
			+ type 
			//+ "-" ??
			+ manufacturerCode.toString();
	}
	
//	public ExtendedSerialNumber(byte[] value){
//		if(value.length != ExtendedSerialNumber.size){
//			System.out.println("!length");
//			System.exit(0);
//		}
//		
//		int from = 0;
//		serialNumber = (int) value[0];
//		from += 1;
//		
//		monthYear = new String(value, from, 2);
//		from += 2;
//		
//		type = new String(value, from, 1);
//		from += 1;
//		
//		byte[] b = Arrays.copyOfRange(value, from, from+ManufacturerCode.size);
//		manufacturerCode = new ManufacturerCode(b);
//		from += ManufacturerCode.size;
//	}
}
